package com.pda.gongpin.presenter;


import com.pda.gongpin.bean.FullTrayInStaticsBean;
import com.pda.gongpin.bean.StockAbnormalBean;
import com.pda.gongpin.bean.request.EntryNoRequest;
import com.pda.gongpin.contract.FullTrayInStaticsContract;
import com.pda.gongpin.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import java.util.List;

import io.reactivex.functions.Consumer;

public class FullTrayInStaticsPresenter extends BasePresenter<FullTrayInStaticsContract.View> implements FullTrayInStaticsContract.Presenter {
    @Override
    public void palletEntryStatistics(String body) {
        NetUtils.geApi().getStatistics(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<List<FullTrayInStaticsBean>>>() {
                    @Override
                    public void accept(BaseAppEntity<List<FullTrayInStaticsBean>> listBaseAppEntity) throws Exception {
                        getView().setList(listBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void entryFinish(String entryNo) {
        NetUtils.geApi().entryFinish(entryNo)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<StockAbnormalBean>>() {
                    @Override
                    public void accept(BaseAppEntity<StockAbnormalBean> stockAbnormalBeanBaseAppEntity) throws Exception {
                        getView().showMessage(stockAbnormalBeanBaseAppEntity.getMessage());
                        getView().finishActivity();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
